<template>
  <div class="login-container">
    <div class="login-form">
      <div class="header">
        <img :src="icon" />
        奥鹏图书
      </div>
      <el-form
        :model="form"
        status-icon
        :rules="rules"
        label-position="left"
        ref="form"
        label-width="4vw"
        class="main"
      >
        <el-form-item label="用户名" prop="accountName">
          <el-input
            v-model="form.accountName"
            maxlength="15"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            type="password"
            v-model="form.password"
            maxlength="15"
          ></el-input>
        </el-form-item>
        <el-form-item class="center">
          <el-button type="primary" @click="submitForm('form')" style="width:12vw">登陆</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script type="text/babel">
import "element-ui/lib/theme-chalk/index.css";
import icon from "../../asset/images/icon.jpg";

export default {
  data() {
    return {
      icon,
      form: {
        accountName: "",
        password: "",
      },
      rules: {
        accountName: [
          {
            min: 5,
            max: 15,
            message: "长度在 5 到 15 个字符",
            trigger: "blur",
          },
        ],
        password: [
          {
            min: 5,
            max: 15,
            message: "长度在 5 到 15 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      let that = this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          that.$axios.post("/api/v1/user/login",this.form).then(data=>{
            window.location.href="/";
          }).catch(err=>{
            that.$message.error({message:err.data.message,center:true,offset:screen.availHeight*0.32,duration:1200})
          })
        } else {
          return false;
        }
      });
    },
  },
  computed: {},
  mounted() {},
  beforeMount() {},
};
</script>
<style lang="css" scoped>
@import "../../asset/css/global.css";
.login-container {
  width: 100vw;
  height: 100vh;
  position: absolute;
}

.login-container::after {
  content: "";
  background: url("../../asset/images/login-back.jpeg");
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  opacity: 0.8;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  position: absolute;
  z-index: -1;
}
.login-form {
  width: 24vw;
  height: 17vw;
  margin: 0 auto;
  margin-top: 32vh;
  background-color: white;
  border-radius: 0.875vw;
  padding: 1vw;
}
.login-form .header {
  display: inline-flex;
  width: 20vw;
  font-size: 2vw;
  text-align: center;
  margin-left: 5.75vw;
}
.login-form .header img {
  width: 2vw;
  margin-right: 0.5vw;
}
.login-form .main{
  margin-top: 2vw;
}
</style>